<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <!-- when using the mode "code", it's important to specify charset utf-8 -->
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">

    <link href="../js/jsoneditor/jsoneditor.min.css" rel="stylesheet" type="text/css">
    <script src="../js/jsoneditor/jsoneditor.min.js"></script>
    <script src="../js/jquery-2.1.4.min.js"></script>
</head>
<body>
<p>
    <button onclick="setJSON();">Set JSON</button>
    <button onclick="getJSON();">Get JSON</button>
</p>
<div id="jsoneditor" style="width: 98%; height: 700px;"></div>
<div><pre id="t1"></pre></div>

<script>
    // create the editor
    var container = document.getElementById("jsoneditor");
    
    var options = {
   	    mode: 'code',
   	    modes: ['code', 'form', 'text', 'tree', 'view'], // allowed modes
   	    onError: function (err) {
   	      alert(err.toString());
   	    },
   	    onModeChange: function (newMode, oldMode) {
   	      console.log('Mode switched from', oldMode, 'to', newMode);
   	    }
 	};
    
    var editor = new JSONEditor(container, options);

    // set json
    function setJSON () {
        var json = {
            "Array": [1, 2, 3],
            "Boolean": true,
            "Null": null,
            "Number": 123,
            "Object": {"a": "b", "c": "d"},
            "String": "Hello World"
        };
        editor.set(json);
    }

    // get json
    function getJSON() {
        var json = editor.get();
        alert(JSON.stringify(json, null, 2));
        $('#t1').html(JSON.stringify(json, null, 2));
    }
</script>
</body>
</html>